x86 hvm: Pre-allocate per-cpu HVM memory before bringing CPUs online
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 18 Jan 2010 10:35:36 +0000 (10:35 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 18 Jan 2010 10:35:36 +0000 (10:35 +0000)
after boot. Avoids doing the allocations on the CPU itself, while in a
not-fully-online state and with irqs disabled. This way we avoid
assertions about irqs being disabled in e.g., tlb flush logic.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/hvm/vmx/vmcs.c
xen/arch/x86/hvm/vmx/vmx.c
xen/arch/x86/smpboot.c
xen/include/asm-x86/hvm/hvm.h
xen/include/asm-x86/hvm/vmx/vmcs.h

index 53697b37613ad005def1b2c6faede1c16f1f4c51..8b12d515f97f75d0ad50eca5b663b03feea5d341 100644 (file)
@@ -809,6 +809,16 @@ static int svm_do_pmu_interrupt(struct cpu_user_regs *regs)
     return 0;
 }
 
+static int svm_cpu_prepare(unsigned int cpu)
+{
+    if ( ((hsa[cpu] == NULL) &&
+          ((hsa[cpu] = alloc_host_save_area()) == NULL)) ||
+         ((root_vmcb[cpu] == NULL) &&
+          ((root_vmcb[cpu] = alloc_vmcb()) == NULL)) )
+        return -ENOMEM;
+    return 0;
+}
+
 static int svm_cpu_up(struct cpuinfo_x86 *c)
 {
     u32 eax, edx, phys_hsa_lo, phys_hsa_hi;   
@@ -823,10 +833,7 @@ static int svm_cpu_up(struct cpuinfo_x86 *c)
         return 0;
     }
 
-    if ( ((hsa[cpu] == NULL) &&
-          ((hsa[cpu] = alloc_host_save_area()) == NULL)) ||
-         ((root_vmcb[cpu] == NULL) &&
-          ((root_vmcb[cpu] = alloc_vmcb()) == NULL)) )
+    if ( svm_cpu_prepare(cpu) != 0 )
         return 0;
 
     write_efer(read_efer() | EFER_SVME);
@@ -1231,6 +1238,7 @@ static void svm_invlpg_intercept(unsigned long vaddr)
 
 static struct hvm_function_table __read_mostly svm_function_table = {
     .name                 = "SVM",
+    .cpu_prepare          = svm_cpu_prepare,
     .cpu_down             = svm_cpu_down,
     .domain_initialise    = svm_domain_initialise,
     .domain_destroy       = svm_domain_destroy,
index a6a2f6851c21a4cfdbcd9857b79a957509c30c49..fd16ad2248ac900b97d206c008e12552bdcf51a9 100644 (file)
@@ -320,6 +320,19 @@ static void vmx_load_vmcs(struct vcpu *v)
     local_irq_restore(flags);
 }
 
+int vmx_cpu_prepare(unsigned int cpu)
+{
+    if ( per_cpu(host_vmcs, cpu) != NULL )
+        return 0;
+
+    per_cpu(host_vmcs, cpu) = vmx_alloc_vmcs();
+    if ( per_cpu(host_vmcs, cpu) != NULL )
+        return 0;
+
+    printk("CPU%d: Could not allocate host VMCS\n", cpu);
+    return -ENOMEM;
+}
+
 int vmx_cpu_up(void)
 {
     u32 eax, edx;
@@ -367,15 +380,8 @@ int vmx_cpu_up(void)
 
     INIT_LIST_HEAD(&this_cpu(active_vmcs_list));
 
-    if ( this_cpu(host_vmcs) == NULL )
-    {
-        this_cpu(host_vmcs) = vmx_alloc_vmcs();
-        if ( this_cpu(host_vmcs) == NULL )
-        {
-            printk("CPU%d: Could not allocate host VMCS\n", cpu);
-            return 0;
-        }
-    }
+    if ( vmx_cpu_prepare(cpu) != 0 )
+        return 0;
 
     switch ( __vmxon(virt_to_maddr(this_cpu(host_vmcs))) )
     {
index 48cd0d6665531bf21cf6b74b3196aa4afa039add..8cf971a45c2f6928ce75ab217b8c842b1cbbbb4e 100644 (file)
@@ -1377,6 +1377,7 @@ static void vmx_set_info_guest(struct vcpu *v)
 
 static struct hvm_function_table __read_mostly vmx_function_table = {
     .name                 = "VMX",
+    .cpu_prepare          = vmx_cpu_prepare,
     .domain_initialise    = vmx_domain_initialise,
     .domain_destroy       = vmx_domain_destroy,
     .vcpu_initialise      = vmx_vcpu_initialise,
index ce18c7f0bef77f2b382275db3e77a56a4b7a44b9..26eb1e97a86b94af25fcd901b506e92b57d9a8a7 100644 (file)
@@ -1518,7 +1518,11 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm)
 
 int __devinit __cpu_up(unsigned int cpu)
 {
-       int ret = 0;
+       int ret;
+
+       ret = hvm_cpu_prepare(cpu);
+       if (ret)
+               return ret;
 
        /*
         * We do warm boot only on cpus that had booted earlier
index 1697c8b31bcf600de387b5098a2108ad0f8ad152..0ae7e7ea0a868ae93e3231b7636ee3596116bb68 100644 (file)
@@ -111,6 +111,7 @@ struct hvm_function_table {
     int  (*event_pending)(struct vcpu *v);
     int  (*do_pmu_interrupt)(struct cpu_user_regs *regs);
 
+    int  (*cpu_prepare)(unsigned int cpu);
     int  (*cpu_up)(void);
     void (*cpu_down)(void);
 
@@ -290,11 +291,15 @@ uint8_t hvm_combine_hw_exceptions(uint8_t vec1, uint8_t vec2);
 void hvm_set_rdtsc_exiting(struct domain *d, bool_t enable);
 int hvm_gtsc_need_scale(struct domain *d);
 
+static inline int
+hvm_cpu_prepare(unsigned int cpu)
+{
+    return (hvm_funcs.cpu_prepare ? hvm_funcs.cpu_prepare(cpu) : 0);
+}
+
 static inline int hvm_cpu_up(void)
 {
-    if ( hvm_funcs.cpu_up )
-        return hvm_funcs.cpu_up();
-    return 1;
+    return (hvm_funcs.cpu_up ? hvm_funcs.cpu_up() : 1);
 }
 
 static inline void hvm_cpu_down(void)
index ed77451afb4416484539b4c02250696174c7d8a5..657ae96252fcf592c67adf478166c6eb7f41a12d 100644 (file)
@@ -26,6 +26,7 @@
 extern void start_vmx(void);
 extern void vmcs_dump_vcpu(struct vcpu *v);
 extern void setup_vmcs_dump(void);
+extern int  vmx_cpu_prepare(unsigned int cpu);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);